# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=mc
pkgver=4.8.23
pkgrel=1
pkgdesc="Midnight Commander is a text based filemanager/shell that emulates Norton Commander"
arch=('i686' 'x86_64')
url="https://www.midnight-commander.org/"
license=('GPL')
depends=('glib2'
         'libssh2')
makedepends=('glib2-devel' 'libssh2-devel' 'ncurses-devel')
optdepends=('gawk: hp48+ extfs'
            #'aspell: spelling corrections'
            'cvs: CVS support'
            'perl: needed by several extfs scripts'
            #'unace: uace extfs'
            #'unarj: uarj extfs'
            'unrar: urar extfs'
            'zip: uzip extfs'
            'p7zip: support for 7zip archives')
options=('!emptydirs' '!makeflags')
backup=('etc/mc/edit.indent.rc'
        'etc/mc/filehighlight.ini'
        'etc/mc/mcedit.menu'
        'etc/mc/mc.ext'
        'etc/mc/mc.keymap'
        'etc/mc/mc.menu'
        'etc/mc/sfs.ini')
source=(${pkgname}-${pkgver}.tar.gz::"https://github.com/MidnightCommander/${pkgname}/archive/${pkgver}.tar.gz"
        4.7.5.2-ncursesw-term.h.patch
        mc-4.8.19-msys2.patch)
sha256sums=('732024636611f1d770a4324204eef4b9ac840ec37a9d3c3476087278962e3f90'
            '49e9a7d918088c8760b0090e99cd6257fa56efa3a4d3e6c9166270cda9c2e8e3'
            '3ed05c91c9e6f2004808a943898188ca9deb15d8df918917f36a32676b733b94')
noextract=(${pkgname}-${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/${pkgname}-${pkgver} ]] && rm -rf ${srcdir}/${pkgname}-${pkgver}
  tar -xzf ${srcdir}/${pkgname}-${pkgver}.tar.gz -C ${srcdir} || true
  
  cd "${srcdir}/${pkgname}-${pkgver}"
  cp -f doc/{INSTALL,NEWS,README} .
  
  ./autogen.sh
  
  patch -Np2 -i "${srcdir}/4.7.5.2-ncursesw-term.h.patch"
  patch -Np1 -i "${srcdir}/mc-4.8.19-msys2.patch"

  autoreconf -fi

}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  ./configure --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --without-libintl-prefix \
    --without-libiconv-prefix \
    --with-screen=ncursesw \
    --enable-charset \
    --libexecdir=/usr/lib

  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  make DESTDIR="${pkgdir}" install

  # Fix FS#15177
  sed 's|op_has_zipinfo = 0|op_has_zipinfo = 1|' \
    -i "${pkgdir}/usr/lib/mc/extfs.d/uzip"

  sed 's#/usr/bin/env python#/usr/bin/python2#' \
    -i "${pkgdir}/usr/lib/mc/extfs.d/s3+"
}
